<template>
 <div>
   <el-row>
     <el-col :span=24>
        <div style="float: left"> 
         <label for="assistant" style="font-size:20px;font-weight: 600; line-height: 40px;margin-right:5px">信息变更列表</label>
       </div>
       <div class="header" style="width:120px;margin:0 10px 0 30px">
         <el-input v-model="form.name" auto-complete="off" placeholder="输入姓名" clearable></el-input>
       </div>
       <div class="header">
         <el-button type="primary" icon="el-icon-search" @click="getTableData();getSearchName()" circle></el-button>
       </div>
       <div style="width:90px;float:right;margin:0 50px 0 50px">
         <el-button type="danger" icon="el-icon-close" @click="checkNoPass(multipleSelection)" round>审核不通过</el-button>
       </div>  
       <div style="width:90px;float:right;margin-left:10px;">
         <el-button type="success" icon="el-icon-check" @click="checkPass(multipleSelection)" round>审核通过</el-button>
       </div>       
     </el-col>
   </el-row>
   <el-row style="border-top: 1px solid black; margin-top: 15px">
      <el-table
        @selection-change="handleSelectionChange"
        v-loading="loading"
        :data="tableData"
        style="width: 100%;margin-bottom: 10px;padding-left:5px;padding-right:5px">
        <el-table-column
        type="selection"
        width="55">
        </el-table-column>
        <el-table-column
          prop="id"
          label="id"
          width="90">
        </el-table-column>
        <el-table-column
          label="姓名"
          prop="name"
          width="150">
        </el-table-column>
        <el-table-column
          label="身份证号"
          prop="idnumber"
          width="250">
        </el-table-column>
        <el-table-column
          label="性别"
          prop="sex"
          width="160">
        </el-table-column>
        <el-table-column
            label="最高学历"
            prop="edu"
            width="210">
          </el-table-column>
        <el-table-column
          label="工作单位"
          prop="sch"
          width="230">
        </el-table-column>
        <el-table-column
          label="专业技术职务"
          prop="majoroccupation"
          width="210">
        </el-table-column>
        <el-table-column
          label="办公电话"
          prop="office"
          width="180">
        </el-table-column>
        <el-table-column
          label="操作"
          width="130">
          <template slot-scope="scope">
            <!-- name的值是配置路由文件对某界面的命名name，接受值this.$route.params.id -->
            <router-link :to="{name: 'personchange',
                              params: {id: scope.row.id,
                                       searchName: searchName
                                      }
                              }" 
                              class="btn-link edit-btn el-icon-s-check"
                              style="background-color: #409EFF">
            查看修改
            </router-link>
          </template>
        </el-table-column>
      </el-table>
   </el-row>
   <el-row>
    <el-pagination
      v-show="allPage>1"
      layout="prev, pager, next"
      :page-count="allPage"
      :current-page="nowPage"
      @current-change="goPage" 
      class="pull-right" background>
    </el-pagination>
   </el-row>
 </div>
</template>

<script>
import http from '../../../../src/assets/js/http'
export default {
  data () {
    return {
      nowPage: 1,
      allPage: 1,
      form: {
        name: ''
      },
      tableData: [],
      loading: true,
      userInfo: Lockr.get('userInfo'),
      multipleSelection: [],
      searchName: {}
    }
  },
  methods: {
    init() {
      // console.log(this.userInfo)
      this.getTableData()
    },
    // 保存搜索名字
    getSearchName() {
      this.searchName = {
        name: this.form.name
      }
    },
    // 复选框信息
    handleSelectionChange(val) {
      this.multipleSelection = val
    }, 
    getTableData() {
      // 2是高校老师，3/9是教育厅和admin
      if(this.userInfo.level === 2) {
        if(this.$route.params.searchName === undefined) {
          var data = {
            sch: this.userInfo.sch,
            name: this.form.name,
            page: this.nowPage
            } 
          } else {
            var data = {
            sch: this.userInfo.sch,
            name: this.$route.params.searchName.name,
            page: this.nowPage
            } 
            this.form = this.$route.params.searchName
          }
        console.log(data)
        this.apiPost('admin/Train/TeacherChangelist', data).then((res) => {
          this.handelResponse(res, (data) => {
            console.log(res)
            this.tableData = []
            data.data.forEach((element) => {
              this.tableData.push({
                id: element.id,
                name: element.name,
                office: element.office,
                idnumber: element.idnumber,
                sch: Lockr.get('schInfo')['sch_id_'+element.sch].sch_name,
                sex: element.sex == 1 ? '男':'女',
                edu: element.edu,
                majoroccupation: element.majoroccupation
              })
            })
            this.allPage = data.data.last_page
            this.loading = false
          })
        })
      } else if(this.userInfo.level === 3||9) {
        if(this.$route.params.searchName === undefined) {
          var data = {
            name: this.form.name,
            page: this.nowPage
          } 
        } else {
          var data = {
          name: this.$route.params.searchName.name,
          page: this.nowPage
          } 
          this.form = this.$route.params.searchName
        }
        console.log(data)
        this.apiPost('admin/Train/EduChangelist', data).then((res) => {
          this.handelResponse(res, (data) => {
            console.log(res)
            this.tableData = []
            res.data.forEach((element) => {
              this.tableData.push({
                id: element.id,
                name: element.name,
                office: element.office,
                idnumber: element.idnumber,
                sch: Lockr.get('schInfo')['sch_id_'+element.sch].sch_name,
                sex: element.sex == 1 ? '男':'女',
                edu: element.edu,
                majoroccupation: element.majoroccupation
              })
            })
            this.allPage = res.data.last_page
            this.loading = false
          })
        })
      }    
    },
    // 审核通过
    checkPass(row) {
      if(row.length >= 1) {
        this.$confirm('确认选中辅导员审核通过吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _g.openGlobalLoading()
        let ids = []
        for(let i = row.length-1; i >= 0; i --) {
          ids[i] = row[i].id
        }
        let data = {
          id: ids,
          status: 2,
          sch: this.userInfo.sch
        }
        console.log(data)
          this.apiPost('admin/Train/EduChangecheck', data).then((res) => {
            _g.closeGlobalLoading()
            this.handelResponse(res, (data) => {
              _g.toastMsg('success', '审核成功')
              if (row.length === 1 && this.nowPage !== 1) {
                this.nowPage = this.nowPage - 1
                this.goPage(this.nowPage)
              } else {
                this.goPage(this.nowPage)
              }
            })
          })
      }).catch(() => {
        // handle error
        })
      } else {
        _g.toastMsg('warning', '请至少选择一项！')
      }
    },
     // 审核不通过
    checkNoPass(row) {
      if(row.length >= 1) {
        this.$confirm('确认选中辅导员审核不通过吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _g.openGlobalLoading()
        let ids = []
        for(let i = row.length-1; i >= 0; i --) {
          ids[i] = row[i].id
        }
        let data = {
          id: ids,
          status: 3,
          sch: this.userInfo.sch
        }
        console.log(data)
          this.apiPost('admin/Train/EduChangecheck', data).then((res) => {
            _g.closeGlobalLoading()
            this.handelResponse(res, (data) => {
              _g.toastMsg('success', '审核不通过')
              if (row.length === 1 && this.nowPage !== 1) {
                this.nowPage = this.nowPage - 1
                this.goPage(this.nowPage)
              } else {
                this.goPage(this.nowPage)
              }
            })
          })       
      }).catch(() => {
        // handle error
        })
      } else {
          _g.toastMsg('warning', '请至少选择一项！')
      }
    },
    // 选择页面
    goPage(num) {
        this.nowPage = num
        this.getTableData()
      },
  },
  created() {
    _g.closeGlobalLoading()
    this.init()
  },
  mounted() {
  },
  computed: {
  },
  components: {
  },
  mixins: [http]
}

</script>
<style scoped>
  .header {
     float: left;
     margin-left: 10px;
  }
</style>
